//
//  StretchableTableHeaderView.m
//  StretchableTableHeaderView
//

#import "HFStretchableTableHeaderView.h"

@interface HFStretchableTableHeaderView()
{
    CGRect initialFrame;
    CGFloat defaultViewHeight;
    CGRect initialImgeFrame;
    CGRect  initialshareFrame;
    CGRect  initialscoreFrame;
    CGRect  initialheaderFrame;
    CGFloat defaultimageHeight;
    CGFloat defaultimageY;
    
    
    CGFloat defaultScoreY;
    CGFloat defaultShareY;
    CGFloat defaultHeaderY;
    CGFloat defaultxingixngY;
    CGFloat defaulterweimaY;

}
@end


@implementation HFStretchableTableHeaderView

- (void)stretchHeaderForTableView:(UITableView*)tableView withView:(UIView*)view imageView:(UIImageView *)backImageView share:(UILabel *)name headerImaheView:(UIImageView *)header erweima:(UIImageView *)erweima
{
    
    _tableView                   = tableView;
    _view                        = view;
    initialFrame                 = _view.frame;
    defaultViewHeight            = initialFrame.size.height;
    _imageView                   = backImageView;
    initialImgeFrame             = backImageView.frame;
    defaultimageY                = backImageView.origin.y;
    defaultimageHeight           = backImageView.size.height;
    
    _name                        = name;
    _erweima                     = erweima;
    _header                      = header;
    defaultShareY                = name.origin.y;
    defaulterweimaY              = erweima.origin.y;
    defaultHeaderY               = header.origin.y;
    
    UIView* emptyTableHeaderView = [[UIView alloc] initWithFrame:initialFrame];
    _tableView.tableHeaderView   = emptyTableHeaderView;
    [_tableView addSubview:_view];
}

- (void)scrollViewDidScroll:(UIScrollView*)scrollView
{
    if(scrollView.contentOffset.y < 0) {
        CGFloat offsetY = (scrollView.contentOffset.y + scrollView.contentInset.top) * -1;
        initialFrame.origin.y = offsetY * -1;
        initialFrame.size.height = defaultViewHeight + offsetY;
        _view.frame = initialFrame;
        
        initialImgeFrame.size.height = defaultimageHeight + offsetY;
        _imageView.frame = initialImgeFrame;
        
        
        
        CGRect shreFrame = _name.frame;
        shreFrame.origin.y = defaultShareY + offsetY;
        _name.frame = shreFrame;
        
        CGRect headerFrame = _header.frame;
        headerFrame.origin.y = defaultHeaderY + offsetY;
        _header.frame = headerFrame;
        
    
        
        CGRect erweimaFrame = _erweima.frame;
        erweimaFrame.origin.y = defaulterweimaY + offsetY;
        _erweima.frame = erweimaFrame;

        
    }
}

@end
